package com.matrix.review.listener;

import com.matrix.common.constant.RocketMQConstants;
import com.matrix.review.service.ReviewStatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author 有点甜
 * @since 2025/7/29
 */
@Slf4j
@Component
@RequiredArgsConstructor
@RocketMQMessageListener(topic = RocketMQConstants.REVIEW_STATS_TOPIC,
        consumerGroup = RocketMQConstants.REVIEW_STATS_CONSUMER_GROUP)
public class ReviewStatListener implements RocketMQListener<Long> {

    private final ReviewStatService reviewStatService;

    @Override
    public void onMessage(Long reviewId) {
        log.info("收到评价统计任务消息,评价ID: {}", reviewId);
        reviewStatService.updateShopAndProductRating(reviewId);
    }
}
